import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Dimension;

/**
 * 
 *Gui of Book Management window for the user's use
 */

public class BookManagementGui extends JPanel implements ActionListener 
{
	public static final long serialVersionUID = 1L;
	public JLabel BookManageTitle = null;
	public JButton addSubject = null;
	public JButton addField = null;
	public JButton logout1 = null;
	public JButton cancel = null;
	public JPanel panel = new JPanel();  //  @jve:decl-index=0:visual-constraint="10,30"	
/////////////////////////////yaniv///////////////////////////////	
	public JButton jARUButton = null;
	public JButton jRestorBButton = null; 
	/** book management flag - Indicate that the user entered book management window */
	public boolean BMflage = false;
/////////////////////////////yaniv////////////////////////////////
		
	/**
	 * This is the default constructor
	 */
	public BookManagementGui() {
		super();
		initialize();		
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
public void initialize() {		
		panel.setLayout(null);
		panel.add(getBookManageTitle(), null);
		panel.add(getLogout1(), null);
		panel.add(getaddSubject(), null);	
		panel.add(getaddField(), null);	
		panel.add(getCancel(), null);
		panel.setVisible(false);
		panel.setSize(new Dimension(530, 250));
		panel.setEnabled(false);
		panel.add(getJARUButton(), null);
		panel.add(getJRestorBButton(), null);
	}
	/**
	 * This method initializes Title 
	 * 	
	 * @return javax.swing.JLabel	
	 */
	public JLabel getBookManageTitle() 
	{
		if (BookManageTitle == null) {
			BookManageTitle = new JLabel("Book Management");
			BookManageTitle.setFont(new Font("David",Font.ITALIC,30));
			BookManageTitle.setBounds(new Rectangle(120, 38, 283, 44));
		}
		return BookManageTitle;
	}		
	/**
	 * This method initializes addSubject and set listener on this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getaddSubject() 
	{
		if (addSubject == null) {
			addSubject = new JButton("Add/Remove Subject");
			addSubject.setBounds(new Rectangle(250, 100, 180, 30));
			addSubject.addActionListener(this);			
		}
		return addSubject;
	}
		/**
	 * This method initializes addField and set listener on this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getaddField() 
	{
		if (addField == null) {
			addField = new JButton("Add/Remove Field");
			addField.setBounds(new Rectangle(250, 144, 180, 30));
			addField.addActionListener(this);			
		}
		return addField;
	}
		/**
	 * This method initializes Cancel and set listener on this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getCancel() {
		if (cancel == null) {
			cancel = new JButton("Back");
			cancel.setBounds(new Rectangle(318, 8, 74, 24));
			cancel.addActionListener(this);
		}
		return cancel;
	}
	/**
	 * This method initializes logout1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	JButton getLogout1() {
		if (logout1 == null) {
			logout1 = new JButton("Logout");
			logout1.setBounds(new Rectangle(402, 8, 74, 24));
			logout1.addActionListener(this);
		}
		return logout1;
	}


	public void actionPerformed(ActionEvent ae)
	{		
		if(ae.getSource()==addSubject)
			Main.bookManagementCTRL.o_addSubject(this.panel);
			
		
		if(ae.getSource()==addField)
		{
			Main.bookManagementCTRL.o_addField(this.panel);
			
		}
		if(ae.getSource()==cancel)
			Main.bookManagementCTRL.o_cancel();
		
		if(ae.getSource()==getLogout1())
			Main.bookManagementCTRL.o_logout(this.panel);
		
////////////////////////////////////////////yaniv/////////////////////////////////		
		if(ae.getSource()== getJARUButton() )
		{
			Main.bookManagement.BMflage=true;
			Main.bookManagement.panel.setEnabled(false);
			Main.bookManagement.panel.setVisible(false);
			Main.searchBookC = new SearchBookCONTROL();
			Main.searchBookG = new SearchBookGUI();
			Main.log.frame.setSize(730, 560);
			Main.log.frame.add(Main.searchBookG);
			Main.searchBookG.setEnabled(true);
			Main.searchBookG.setVisible(true);
		}
		if(ae.getSource()== getJRestorBButton())
		{
			Main.restoreBC = new RestoreBookC();
			Main.restoreBC.retriveDeletedB();
			if (!Main.welcomeScreen.errorflag)
			{	
				Main.bookManagement.panel.setEnabled(false);
				Main.bookManagement.panel.setVisible(false);
				Main.restoreBG = new RestoreBookG();
				Main.log.frame.setSize(680, 380);
				Main.log.frame.add(Main.restoreBG);
				Main.restoreBG.setEnabled(true);
				Main.restoreBG.setEnabled(true);
			}
			else
			{
				//do nothing
			}
			
		}
	}

	/**
	 * This method initializes jARUButton and set listener on this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJARUButton() {
		if (jARUButton == null) {
			jARUButton = new JButton();
			jARUButton.setLayout(new BorderLayout());
			JLabel label1 = new JLabel("To Add/ Remove/ Update");
			JLabel label2 = new JLabel("Please Click Here");
			jARUButton.add(BorderLayout.NORTH,label1);
			jARUButton.add(BorderLayout.SOUTH,label2);
			jARUButton.setBounds(new Rectangle(30, 100, 180, 51));
			jARUButton.addActionListener(this);
		}
		return jARUButton;
	}

	/**
	 * This method initializes jRestorBButton and set listener on this button
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJRestorBButton() {
		if (jRestorBButton == null) {
			jRestorBButton = new JButton();
			jRestorBButton.setBounds(new Rectangle(28, 164, 180, 30));
			jRestorBButton.setText("Restore Deleted Book");
			jRestorBButton.addActionListener(this);
		}
		return jRestorBButton;
	}
////////////////////////////////////////////yaniv/////////////////////////////////

}
